import { AppDispatch } from '@/store';
import http from '@/utils/request';
import { setTokenInfo } from '@/utils/storage';

// 发送手机验证码
export const sendCodes = (mobile: string) => {
  return async (dispatch: AppDispatch) => {
    const res = await http.get(`/v1_0/sms/codes/${mobile}`);
    console.log('验证码请求', res);
  };
};

// 用户认证
export const Authorizations = ({
  mobile,
  code,
}: {
  mobile: string;
  code: string;
}) => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post('/v1_0/authorizations', { mobile, code });
    // 保存到 redux
    dispatch({ type: 'user/saveAuth', payload: res.data });
    // 保存到 本地存储
    setTokenInfo(res.data);
  };
};
